package com.example.ex3demo;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    TextView tv_action_text;
    Button btn_listener_of_activity;
    Button btn_listener_of_inner_class;
    Button btn_listener_of_anonymous_inner_class;
    Button btn_listener_of_lambda;
    Button btn_listener_of_outer_class;

    @BindView(R.id.btn_listener_of_bind)
    Button btn_listener_of_bind;

    Button btn_show_system_info;
    Button btn_show_progress_bar;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ButterKnife.bind(this);

        tv_action_text = findViewById(R.id.tv_action_text);
        btn_listener_of_activity = findViewById(R.id.btn_listener_of_activity);
        btn_listener_of_inner_class = findViewById(R.id.btn_listener_of_inner_class);
        btn_listener_of_anonymous_inner_class = findViewById(R.id.btn_listener_of_anonymous_inner_class);
        btn_listener_of_lambda = findViewById(R.id.btn_listener_of_lambda);
        btn_listener_of_outer_class = findViewById(R.id.btn_listener_of_outer_class);
        btn_listener_of_bind = findViewById(R.id.btn_listener_of_bind);
        btn_show_system_info = findViewById(R.id.btn_show_system_info);
        btn_show_progress_bar = findViewById(R.id.btn_show_progress_bar);

        //ACTIVITY作为监听器
        btn_listener_of_activity.setOnClickListener(this);

        //内部类作为监听器
        btn_listener_of_inner_class.setOnClickListener(new MyListener());

        //匿名内部类作为监听器
        btn_listener_of_anonymous_inner_class.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                tv_action_text.setText(((Button) view).getText());
            }
        });

        //LAMBDA表达式作为监听器
        btn_listener_of_lambda.setOnClickListener(view ->
                tv_action_text.setText(((Button) view).getText())
        );

        //外部类作为监听器
        btn_listener_of_outer_class.setOnClickListener(new OutClassViewClickListener() {
            @Override
            public void onClick(View view) {
                tv_action_text.setText(((Button) view).getText());
            }
        });

        //系统信息
        btn_show_system_info.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, SystemInfoActivity.class);
                startActivity(intent);
            }
        });

        //显示进度条
        btn_show_progress_bar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, ProgressDialogTest.class);
                startActivity(intent);
            }
        });
    }

    @OnClick(R.id.btn_listener_of_bind)
    public void onClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_listener_of_bind:
                tv_action_text.setText(((Button) view).getText());
        }
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.btn_listener_of_activity) {
            tv_action_text.setText(((Button) view).getText());
        }
    }

    //内部类监听器
    class MyListener implements View.OnClickListener {

        @Override
        public void onClick(View view) {
            tv_action_text.setText(((Button) view).getText());
        }
    }
}